﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BestCode.Creds.Data
{
    public class DataFactory
    {
        #region Constructor
        static DataFactory instance = null;
        public static DataFactory Current
        {
            get
            {
                if (instance == null)
                    instance = new DataFactory();
                return instance;
            }
        }
        public T GetInstance<T>(string className)
        {
            return Create<T>("BestCode.Creds.Data." + className + ",BestCode.Creds.Data");
        }
        public static T Create<T>(string classFullName)
        {
            var result = (T)BestCode.Core.Reflection.InstanciateObjectFromAssembly(classFullName);
            if (result == null)
                throw new NullReferenceException("cannot create instance of type " + classFullName);
            return result;
        }
        #endregion

        public ITemplateDao GetTemplateDao()
        {
            return this.GetInstance<ITemplateDao>("TemplateDao");
        }


        public IEntityDao GetEntityInfoDao()
        {
            return this.GetInstance<IEntityDao>("EntityDao");
        }


        public ILayoutDao GetLayoutDao()
        {
            return this.GetInstance<ILayoutDao>("LayoutDao");
        }


        public IFieldDefinitionDao GetFieldDefinitionDao()
        {
            return this.GetInstance<IFieldDefinitionDao>("FieldDefinitionDao");
        }

        public IEntityChildDao GetEntityChildDao()
        {
            return this.GetInstance<IEntityChildDao>("EntityChildDao");
        }

        public ISummaryDao GetReportSummaryDao()
        {
            return this.GetInstance<ISummaryDao>("SummaryDao");
        }

        public IAttachmentDao GetAttachmentDao()
        {
            return this.GetInstance<IAttachmentDao>("AttachmentDao");
        }
    }
}
